iT邦幫忙

2024 iThome 鐵人賽

DAY 5
0
Python

一起來用 Snakify 練練手系列 第 5

【一起來用 Snakify 練練手】Day5 Lesson 2 練習題參考解答

  • 分享至 

  • xImage
  •  

Lesson2 開始就有一些進階題目
大家可以試著思考一下
有一些題目只是在考邏輯 不用想的太難
下面也將提供各題參考解答
(⭐代表加碼題目)

  • Last digit of integer (%)
a = int(input())
print(a%10)
  • ⭐Two digits (%//)
a = int(input())
print(a//10, a%10)
  • ⭐Swap digits (%//)
a = int(input())
print(str(a%10)+str(a//10))
  • ⭐Last two digits (%)
a = int(input())
print(a%100)
  • Tens digit (%//)
a = int(input())
print((a//10)%10)
  • Sum of digits (%//)
a = int(input())
print(a//100 + a%10 + (a//10)%10)
  • ⭐Reverse three digits (%//)
a = int(input())
print(str(a%10) + str(a//10%10) + str(a//100))
  • ⭐Merge two numbers (%//)
a = int(input())
b = int(input())
print(str(a//10) + str(b//10) + str(a%10) + str(b%10))
  • ⭐Cyclic rotation (%//*)
a = int(input())
print(str(a%100//10) + str(a%100%10) + str(a//100//10) + str(a//100%10))
  • Fractional part (float())
a = float(input())
print(a-int(a))
  • First digit after decimal point (float()/*)
a = float(input())
print(int(a*10%10))
  • Car route (ceil())
from math import ceil
n = int(input())
m = int(input())
print(ceil(m/n))
  • ⭐Day of week (%)
a = int(input())
print((a+3)%7)
  • Digital clock (%//)
a = int(input())
print(str(a//60), str(a%60))
  • Total cost (%//*)
  • ⭐Century (//)
a = int(input())
b = int(input())
c = int(input())

n = c*a*100+c*b
print(n//100, n%100)
  • ⭐Snail (ceil())
a = int(input())
print((a+99)//100)
  • Clock face - 1 (/*)
import math as m

h = int(input())
a = int(input())
b = int(input())

print(m.ceil((h-a)/(a-b))+1)
  • Clock face - 2 (/*%)
h = int(input())
m = int(input())
s = int(input())

print(h*30 + m*0.5 + s*(360/12/60/60))

上一篇
【一起來用 Snakify 練練手】Day4 Lesson 2 概念
下一篇
【一起來用 Snakify 練練手】Day6 Lesson 3 概念
系列文
一起來用 Snakify 練練手30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言